﻿app.controller('ProvideHelpController',
    [
    '$rootScope',
    '$scope',
    '$localStorage',
    '$state',
    '$stateParams',
    '$modal',
    'ManagerPackFactory', 'BitcoinFactory', '$filter', 'CN_TructiepFactory', 'commonFactory',
function ($rootScope, $scope, $localStorage, $state, $stateParams, $modal, ManagerPackFactory, BitcoinFactory, $filter, CN_TructiepFactory) {
    $scope.title = "PH Detail",
    $scope.messeger = "",
    $scope.orderId = $stateParams.orderId,
    $scope.popup = function (windowClass, StyleModal, Controller, size, param) {
        $modal.open({
            windowClass: windowClass,
            templateUrl: StyleModal,
            controller: Controller,
            size: size,
            resolve: {
                messeger: function () {
                    return $scope.messeger;
                },
                title: function () {
                    return $scope.title;
                },
                param: function () {
                    return param;
                }
            }
        })
    },
    $scope.ProvideHelpList = [],
    LoadProvideHelp($localStorage.UserId);
    function LoadProvideHelp(userId) {
        commonFactory.loadProvideHelp(userId).then(
             function successCallback(resp) {
                 if (resp.data.Status) {
                     $scope.showProvideOrder = true;
                     $scope.ProvideHelpList = resp.data.Result;
                 } else {
                     $scope.message = resp.data.Msg;
                 }
             })
    };
    $scope.doPay = function (item) {
        DoPay(item);
    };
    function DoPay(item) {
        var btc = parseFloat(item.Amount).toFixed(8);
        $state.go("app.payorder", { orderId: item.Id_Order, amount: btc, userRecieve: item.UserIdGet });
    }

    $scope.doSent = function (item) {
        sent(item);
    };

    function sent(item) {
        commonFactory.approveProvideOrder2(item.Id, item.RoomCode).then(function (rsp) {
            if (rsp.data.Status) {
                $state.go('app.gethelp')
            } else {
                $scope.messeger = rsp.data.Msg,
                $scope.title = 'Warning',
                $scope.popup('modal-message modal-warning', "WarningModal");
            }
        }, function (error) {
            $scope.status = 'Unable to load profile data: ' + error.message;
        });
    }
}
    ]);